/* $RCSFile: ADNDynQueueItem.cs $
 * Apache license v2 2011 by Christian Surieux
 * $Source: ?/CRMWrapper3/DynEntities/ADNDynQueueItem.cs $
 * $log$
 * Revision 19 2010/10/02 14:01:49  christian.surieux
 *   Corrected a bug in allmost everyADNDyn file for PrimaryFieldVualue
 * Revision 6 2010/08/06 19:56:33  christian.surieux
 *   Added Log to All cs files
 */

using System;
using System.Diagnostics;
using System.Collections;
using System.ComponentModel;
using System.Collections.Generic;
using System.Text;
using CrmSdk;

namespace AddonNice.CRMWrapper
{
	public class ADNDynQueueItem : DynEntity
	{
        protected class Ftor: DFactor
        {
            public Ftor() : base(CrmStr.queueitem)
            {}

            public override Type DynType
            { get { return typeof(ADNDynQueueItem); } }

            public override string DynTypename
            {   get{ return CrmStr.queueitem;}}

            public override DynEntity Build()
            {   return new ADNDynQueueItem();}

            public override DynEntity Build(CRMWrapperBase w, InternalDynamicEntity dEntity, PropertyDescriptorCollection wproperties)
            {   return new ADNDynQueueItem(w, dEntity, wproperties, null);}

            public override DynEntity Build(CRMWrapperBase w, string PrimaryFieldValue)
            {   return new ADNDynQueueItem(w,PrimaryFieldValue);}

            public override DynEntity Build(CRMWrapperBase w,Guid PrimaryKeyValue)
            {   return new ADNDynQueueItem(w,PrimaryKeyValue);}
        }

        static ADNDynQueueItem(){new Ftor();} 

        /// <summary>
        /// No owner but a PrimaryUserid
        /// </summary>
        public override bool HasOwnerProperty
        {
            get
            {
                return false;
            }
        }

        public ADNDynQueueItem(): base()
		{}

        public ADNDynQueueItem(CRMWrapperBase w, string PrimaryFiedlValue)
			: base(w, CrmStr.queueitem)
		{
            if ( PrimaryFiedlValue != string.Empty )
                title    =   PrimaryFiedlValue;
		}

		public ADNDynQueueItem(CRMWrapperBase w, Guid CrmId)
			: base(w,CrmStr.queueitem, CrmId)
		{}

		public ADNDynQueueItem(CRMWrapperBase w, InternalDynamicEntity e)
			: base(w,CrmStr.queueitem,e,null,null)
		{}

		public ADNDynQueueItem(CRMWrapperBase w, InternalDynamicEntity e,PropertyDescriptorCollection prop,InternalColumnSet s)
			: base(w,CrmStr.queueitem,e,prop,s)
		{}

        public ADNDynQueueItem(ResetWrapperHandler fn, string PrimaryFiedlValue)
			: base(fn, CrmStr.queueitem)
		{
            if ( PrimaryFiedlValue != string.Empty )
                title    =   PrimaryFiedlValue;
		}

		public ADNDynQueueItem(ResetWrapperHandler fn, Guid CrmId)
			: base(fn,CrmStr.queueitem, CrmId)
		{}

		public ADNDynQueueItem(ResetWrapperHandler fn, InternalDynamicEntity e)
			: base(fn,CrmStr.queueitem,e,null,null)
		{}

		public ADNDynQueueItem(ResetWrapperHandler fn, InternalDynamicEntity e,PropertyDescriptorCollection prop,InternalColumnSet s)
			: base(fn,CrmStr.queueitem,e,prop,s)
		{}

		/// <summary>
		/// Crm Key
		/// </summary>
        [CrmDynAttribute(CrmStr.queueitem)]
        public Guid queueitemid
		{
			get
			{
				return KeyPropertyValue(CrmStr.queueitemid);
			}
			set
			{
				AddKeyProperty(CrmStr.queueitemid, value);
			}
		}

        protected override void SetCrmIdProperty(Guid crmId)
        {
           if ( !dicProperty.ContainsKey(CrmStr.queueitemid) || KeyPropertyValue(CrmStr.queueitemid) != crmId )
                queueitemid   =   crmId;
        }
        
        public override string PrimaryFieldName
        {
            get
            {
               return CrmStr.title;
            }
           set
           {}
        }

        /// <summary>
        /// Value contained in the PrimaryField for the DynEntity or empty if no PrimaryField
        /// </summary>
        public override string PrimaryFieldStringValue
        {
            get
            {
                return title;
            }
            set
            {
                title =   value;
            }
        }

        public override Guid PrimaryKeyGuidValue
        {
           get
           {
                return queueitemid;
           }
           set
           {
               queueitemid    =   value;
           }
        }

        /// <summary>
        /// Gets or sets the title of the annotation. 
        /// </summary>
        [CrmDynAttribute(CrmStr.queueitem)]
        public string title 
        {
            get
            {
                return StringPropertyValue(CrmStr.title);
            }
            set
            {
                AddStringProperty(CrmStr.title,value);
            }
        }

        [CrmDynAttribute(CrmStr.queueitem)]
        public Guid queueid
		{
			get
			{
				return LookupPropertyValue(CrmStr.queueid);
			}
			set
			{
				AddLookupProperty(CrmStr.queue,CrmStr.queueid, value);
			}
		}

        public string queueName
        {
            get
            {
                if ( ContainsKey(CrmStr.queueid) )
                    return LookupPropertyName(CrmStr.queueid);
                return string.Empty;
            }
        }

        [CrmDynAttribute(CrmStr.queueitem)]
        public string enteredon 
        {
            get
            {
                return DateTimePropertyValue(CrmStr.enteredon);
            }
            set
            {
                AddDateTimeProperty(CrmStr.enteredon,value);
            }
        }

        [CrmDynAttribute(CrmStr.queueitem)]
        public Guid objectid
		{
			get
			{
				return LookupPropertyValue(CrmStr.objectid);
			}
			set
			{
				AddLookupProperty(CrmStr.queue,CrmStr.objectid, value);
			}
		}

        public string objectName
        {
            get
            {
                if ( ContainsKey(CrmStr.objectid) )
                    return LookupPropertyName(CrmStr.objectid);
                return string.Empty;
            }
        }
        /*
            activity 
            activitymimeattachment
            activityparty
            appointment
            bulkoperation
            calendar
            campaignactivity
            campaignresponse
            email
            fax
            incident
            incidentresolution
            letter
            opportunityclose
            orderclose
            phonecall
            quoteclose
            service
            serviceappointment
            task
         */
        public string objecttypecode
		{
			get
			{
				return EntityNameReferencePropertyValue(CrmStr.objecttypecode);
			}
			set
			{
                switch ( value )
                {
                    case CrmStr.activity:
                    case CrmStr.activitymimeattachment:
                    case CrmStr.activityparty:
                    case CrmStr.appointment:
                    case CrmStr.bulkoperation:
                    case CrmStr.calendar:
                    case CrmStr.campaignactivity:
                    case CrmStr.campaignresponse:
                    case CrmStr.email:
                    case CrmStr.fax:
                    case CrmStr.incident:
                    case CrmStr.incidentresolution:
                    case CrmStr.letter:
                    case CrmStr.opportunityclose:
                    case CrmStr.orderclose:
                    case CrmStr.phonecall:
                    case CrmStr.quoteclose:
                    case CrmStr.service:
                    case CrmStr.serviceappointment:
                    case CrmStr.task:
                    AddEntityNameReferenceProperty(CrmStr.objecttypecode,value);
                    break;
                }
			}
		}

        /// <summary>
        /// Gets the ID of the organization associated with the queue
        /// </summary>
        [CrmDynAttribute(CrmStr.queueitem)]
        public override Guid organizationid
        {
            get
            {
                if ( ContainsKey(CrmStr.organizationid) )
                    return LookupPropertyValue(CrmStr.organizationid);
                return Guid.Empty;
            }
        }

        public override string organizationName
        {
            get
            {
                if ( ContainsKey(CrmStr.organizationid) )
                    return LookupPropertyName(CrmStr.organizationid);
                return string.Empty;
            }
        }


        [CrmDynAttribute(CrmStr.queueitem)]
        public int priority
        {
            get
            {
                if ( ContainsKey(CrmStr.priority) )
                    return NumberPropertyValue(CrmStr.priority);
                return 0;
            }
            set
            {
                AddNumberProperty(CrmStr.priority,value);
            }
        }

        [CrmDynAttribute(CrmStr.queueitem)]
        public string sender 
        {
            get
            {
                return StringPropertyValue(CrmStr.sender);
            }
            set
            {
                AddStringProperty(CrmStr.sender,value);
            }
        }

        [CrmDynAttribute(CrmStr.queueitem)]
        public string torecipients 
        {
            get
            {
                return StringPropertyValue(CrmStr.torecipients);
            }
            set
            {
                AddStringProperty(CrmStr.torecipients,value);
            }
        }

        [CrmDynAttribute(CrmStr.queueitem)]
        public int timezoneruleversionnumber
        {
            get
            {
                if ( ContainsKey(CrmStr.timezoneruleversionnumber) )
                    return NumberPropertyValue(CrmStr.timezoneruleversionnumber);
                return 0;
            }
            set
            {
                AddNumberProperty(CrmStr.timezoneruleversionnumber,value);
            }
        }
    }
}
